<?php
//$mailService = new MailService();
//$mailService->registerMail("ovolollo", "paswwwasd", "ameboy@live.it");
class MailService {
	public $style ="<style>.content{background:#662D91;color:white;padding:8px} .mail_info_box {margin-left: 30px;margin-right: 30px;background-color: #FFFFFF;text-align: center;color:black;} .mail_password_label{padding:5px;font-weight: bolder;} .mail_user_label{padding:5px;font-weight: bolder;}</style><div class='content'>";
	public function registerMail($user, $psw, $mail) {
		$language = $this -> getLanguage();
		
		$obj = $user.$language->getLabel("register.mail.object");
		$msg = $language->getLabel("register.mail.message.1").$user.
		$language->getLabel("register.mail.message.2").$psw.
		$language->getLabel("register.mail.message.3").
		$language->getLabel("index.help").
		$language->getLabel("register.mail.message.4").
		$language->getLabel("index.help.explain").
		$language->getLabel("register.mail.message.5");
		
		$this->sendMessage($mail, $obj, $msg);
		
	}
	
	private function sendMessage($mail, $obj, $msg) {
		try{
		    $header = "Content-type: text/html; charset=utf-8\r\n";
			$header  .= "MIME-Version: 1.0\r\n";
			$header .= "To: ".$mail." <".$mail.">\n";
			$header .= "From: [E]go <noreply@ego.com>\n";
			$oggetto = "=?UTF-8?B?".base64_encode($obj)."?=";
			$messaggio = $this->style.$msg."</div><span style='display:none'>";
			mail("",$oggetto,$messaggio,$header);
		}catch(PDOException $e) {
		  	echo 'Exception: '.$e->getMessage();
		}
	}

	private function getLanguage() {
		$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
		if ($lang == "it") {
			include '../resources/Message_IT.php';
		} else if ($lang == "en") {
			include '../resources/Message_EN.php';
		} else {
			include '../resources/Message_EN.php';
		}
		return new Language();
	}
}

?>